﻿using System;
using System.Collections.Generic;
using Domino;

namespace T2ReportsAssistant
{
    public class AddressBookContact
    {
        private Dictionary<string, string> _field;

        public AddressBookContact(NotesDocument document)
        {
            Array items = (document.Items as Array);

            if (items != null)
            {
                _field = new Dictionary<string, string>(items.Length, StringComparer.CurrentCultureIgnoreCase);
                foreach (object iObj in items)
                {
                    NotesItem item = iObj as NotesItem;
                    if (item != null)
                    {
                        _field.Add(item.Name, item.Text);
                    }
                }
            }
        }

        public override string ToString()
        {
            return this["FullName"];
        }

        public string this[string FieldName]
        {
            get
            {
                return _field.ContainsKey(FieldName) ? _field[FieldName] : String.Empty;
            }
        }

        //public string MailServerCN
        //{
        //    get
        //    {
        //        Match match = new Regex(@"CN=(\w+)", RegexOptions.IgnoreCase | RegexOptions.Singleline).Match(this["MailServer"]);
        //        return match.Success ? match.Groups[1].Value : String.Empty;
        //    }
        //}
    }
}
